<template>
  <div class="todo-footer" v-show="totalNumber">
    <label>
      <input type="checkbox" @change="handleSelectAll" :checked="isAll" />
    </label>
    <span> <span>已完成{{finishNumber}}</span>/全部{{totalNumber}} </span>
    <button class="btn btn-danger" @click="handleDeleteFinsih">清除已完成任务</button>
  </div>
</template>

<script>
export default {
  name: "TodoFooter",
  props:['todos','deleteFinish','selectAll'],
  methods:{
    handleDeleteFinsih(){
      this.deleteFinish();
    },
    handleSelectAll(e){
      console.log(e.target.checked);
      this.selectAll(e.target.checked);
    }
  },
  computed:{
    isAll(){
      return this.finishNumber === this.totalNumber && 0 < this.totalNumber;
    },
    finishNumber(){
      return this.todos.reduce((pre,current)=>{
        return current.done ? pre + 1 : pre;
      },0);
      // return this.todos.filter((todo)=>{
      //   return todo.done;
      // }).length;
    },
    totalNumber(){
      return this.todos.length;
    },
  }
};
</script>

<style scoped>
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;
}
.todo-footer label {
  display: inline-block;
  margin-left: 20px;
  cursor: pointer;
}
.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}
.todo-footer button {
  float: right;
  margin-top: 5px;
}
</style>